package com.dayuanit.dy16.ebook.ebookweb.task;

import com.dayuanit.dy16.ebook.ebookweb.entity.Order;
import com.dayuanit.dy16.ebook.ebookweb.enums.OrderStatusEnum;
import com.dayuanit.dy16.ebook.ebookweb.mapper.OrderMapper;
import com.dayuanit.dy16.ebook.ebookweb.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 阿里订单查询 任务
 */
@Component
public class AliQueryOrderTask extends BaseTask {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private IOrderService orderService;

    @Scheduled(cron = "0/15 * * * * ?")
    @Override
    protected void doTask() {
        process();
    }

    private void process() {
        List<Order> orders = orderMapper.listByStatus(OrderStatusEnum.wait_pay.getK(), 1000);
        for (Order order : orders) {
            try {
                logger.info("查询订单{}", order.getId());
                orderService.queryAliOrder(order);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }

    }
}
